<?php

namespace app\controller;

use app\BaseController;
use app\common\business\lib\Str;
use think\App;

class User extends BaseController
{

    protected $business = NULL;
    protected $str = NULL;

    public function __construct(App $app){
        parent::__construct($app);
        $this->str = new Str();

    }

    public function logout(){

        $token = $this->str->createToken('admin');
        $this->redis->delete(config('redis.token').$token);
        return $this->success('退出登陆成功');
    }

    /**
     * @return \think\response\Json
     * 登陆
     */
    public function login(){
        $token = $this->str->createToken('admin');
        $this->redis->set(config('redis.token_pre').$token,[
            "id"=>1,
            "username"=>"admin",
        ]);
//        return $this->success('登陆成功');
//        return $token;
        return $this->success($token);
    }

    /**
     * @return \think\response\Json
     * 注册
     */
    public function register(){
        return $this->success('注册成功');
    }
}